package com.itheima.test03_1;

import java.io.IOException;
import java.net.*;

/*
## 题目3（加强训练）
需求：编写程序，使用UDP协议的发送端给接收端发送一句话：“服务端你好啊！”；然后接收端给发送端返回一句话，内容随意。
 */
public class TestUdpService {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(11111);//我从哪里接收
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length);
        socket.receive(packet);
        System.out.println(new String(bytes,0,packet.getLength()));
        String s="你好哇客户端";
        DatagramPacket packet1 = new DatagramPacket(s.getBytes(), s.getBytes().length, InetAddress.getByName("127.0.0.1"),22222);
        socket.send(packet1);
        socket.close();



    }
}
